package com.dpad.telematicsclientapp.presenter


import com.dpad.telematicsclientapp.mvp.mvp.XPresent
import com.dpad.telematicsclientapp.netlibrary.http.NetInstance
import com.dpad.telematicsclientapp.netlibrary.newapp.entity.OutMessageBean
import com.dpad.telematicsclientapp.ui.HomeActivity
import com.dpad.telematicsclientapp.util.utils.ParameterUtils
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import java.util.*

/**
 * ================================================
 * 作    者：booob
 * 版    本：1.0
 * 创建日期：2018-05-18-0018 17:30
 * 描    述：
 * 修订历史：
 * ================================================
 */
class HomePresenter : XPresent<HomeActivity>() {

    fun getMessageData(map: SortedMap<String, Any>) {
        v.loading("")
        NetInstance.getEventsService().getNewMessageData(ParameterUtils.getHeaser(map), ParameterUtils.getJsonBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : Observer<OutMessageBean> {
                    override fun onComplete() {
                        v.loadingComplete()
                    }

                    override fun onSubscribe(d: Disposable?) {
                        addDisposable(d)
                    }

                    override fun onNext(value: OutMessageBean?) {
                        value!!.let {
                            if (value.code == "00000") {
                                v.showData(it)
                            }
                        }
                    }

                    override fun onError(e: Throwable?) {
                        v.loadingComplete()
//                        v.showNoData()
                    }

                })
    }
}
